var walert = window.alert;

function start_dialog2(id,autocount,countid,callback){
    callback = callback || function(){};
    autocount = autocount || 0;
    countid = countid || null;
    easyDialog.close();
    easyDialog.open({
        container : id,
            fixed : true,
            callback: callback,
            autocount : autocount,  //开启倒计时
            countid : countid
    });
}

String.prototype.format = function()
{
    var args = arguments;
    return this.replace(/\{(\d+)\}/g,               
        function(m,i){
            return args[i];
        });
}

var object = Class.$extend({
    __init__ : function(formater,value,html,num,fangshi,wanfa,mulriple){
        this.formater = formater;
        this.total = num * parseInt(mulriple);//投注数
        //this.total = num;
        this.value = value+"#"+fangshi+"#"+wanfa+"#"+mulriple+"#"+this.total*2; //玩法：方式：倍数:本注金额（一星：单式：一倍：本注金额）。列表表示方式 TODO：其它玩法传值       
        this.innerhtml = html;//用户显示
    },
    get_desc : function(){
       return this.formater.format(this.innerhtml,this.total,this.total*2);
    }
});

var mathine = Class.$extend({
    __init__ : function(args){
        args = args || {};
        this.type = args.type;  //彩票种类
        this.rednummax = args.rednummax;  //红球最大数字
        this.bluenummax = args.bluenummax; //蓝球最大数字
        this.redmin = args.redmin;//红球最小数字
        this.redballs = [];
        this.blueballs = [];
        this.redrequire = args.redrequire;  //红球最小要求个数
        this.bluerequire = args.bluerequire; //篮球最小要求个数,-1表示不需要蓝球
        this.redmax = args.redmax; //红球最大允许个数
        this.bluemax = args.bluemax; //蓝球最大允许个数
        this.buymax = args.buymax; //最大投注金额
        this.formater = args.formater;
        this.needzero = args.needzero;  //是否需要补0
        this.fangshi = args.fangshi;
        this.count = 0; //投注计数
    },
    //组合计数
    C : function(list, num){
        var r=0;
        (function f(t,a,n){
            if (n==0) return r++;
            for (var i=0,l=a.length; i<=l-n; i++){
                f(t.concat(a[i]), a.slice(i+1), n-1);
            }
        })([],list,num);
        return r;
    },
    //排列计数
    P : function(list, num){
        var r=0;
        (function f(t,a,n){
            if (n==0) return r++;
            for (var i=0,l=a.length; i<l; i++){
                f(t.concat(a[i]), a.slice(0,i).concat(a.slice(i+1)), n-1);
            }
        })([],list,num);
        return r;
    },
    reset : function(){
        $(".red_select i").attr('class','icon-white');//清除红球和蓝球的选择状态
        $(".blue_select i").attr('class','icon-white');
        $('.like-red')[0].innerHTML = 0;
        $('.like-red')[1].innerHTML = 0;
        this.redballs = [];
        this.tuoballs = [];
        this.danballs = [];
        this.blueballs = [];
        this.count = 0;
    }, 
    get_balls : function(selector){
        var balls = [];
        //$('.'+color+'_select > i.icon-'+color).each(function(i){
        $(selector).each(function(i){
            balls.push($(this).html());
        });
        return balls;
    },
    selectball : function(){
        this.redballs = this.get_balls('.red_select > i.icon-red');
        this.count = this.redballs.length>this.redrequire ? this.C(this.redballs,this.redrequire):1;

        if(this.bluerequire != -1){
            this.blueballs = this.get_balls('.blue_select > i.icon-blue');    
        }
        
        return this.redballs.length>=this.redrequire&&this.blueballs.length>=this.bluerequire;  //至少满足一注
    },
    duplicate : function(srclist,num){
        for(var i=0;i<srclist.length;i++){
            if(srclist[i]==num) return true;
        }
        return false;
    },
    randballs : function(require,max,min){
        var balls = [];
        if(this.unit == 31 || this.unit == 5){
        	var a = (this.unit == 31 ? require:require+1);
        	while(balls.length < a){
                var num = Math.round(Math.random()*(max-min)+min);
        	var n = Math.round(Math.random()*(2-1)+1);
        	if(!this.duplicate(balls,num)){
                balls.push(num);
                if ((n==2&&balls.length<3)||(balls.length==2&&n==1)){
                	balls.push(num);
                }
            }
        	}
        }
        else{
        while(balls.length<require){
            var num = Math.round(Math.random()*(max-min)+min);
            	if(!this.duplicate(balls,num)){
                    balls.push(num);
                }
            } 
        	if(this.type == "01" || this.type == "07" || this.type == "15"){
        		for(var i = 0; i<balls.length ;i++)
        		{
        			for(var j = i+1; j<balls.length;j++)   {
        				if(balls[i] > balls[j])
        				{
        				    var t =balls[i]
        				    balls[i] = balls[j]
        				    balls[j] = t
        				}
        			}
        		}
        	}
        }
        return balls;
    },
    //计算已选择的注数
    compute_amount : function(){
        var ti = 0;
        var filled = this.selectball();
        if(filled){ // 只有至少选中一注，才计算总注数
            ti = this.bluerequire != -1?this.count * this.blueballs.length:this.count; //加上蓝球后的总注数
        }
        return ti;
    },
    ballclickevent : function (wei,color){
        var self = this;
        if (self.unit == 31 || self.unit == 8 || self.unit == 71){
        	$('.'+wei+' > i.icon-white').click(function(e){
        		if($(this).attr('class') == 'icon-white'){
        		var z = String($(this).html());
        		if (self.unit == 8){
        			var a = ["大","小","单","双"];
        		}
        		else{
        			var a = ["0","1","2","3","4","5","6","7","8","9"];
        		}
        		for (var i=0;i<a.length;i++){
        			if(a[i] == z){
        				$(this).attr('class','icon-'+color);
        			}
        			else{
        				$("."+wei+" i:contains('" + a[i] + "')").attr('class','icon-white');
        			}
        		}
        		}
        		else{
        			$(this).attr('class','icon-white');
        		}
        		var ti = self.compute_amount();
                if(ti>-1){
                    $('.like-red')[0].innerHTML = ti;
                    $('.like-red')[1].innerHTML = ti * 2;
                }
        	});
        	}
    else{
        $('.'+color+'_select > i.icon-white1').click(function(e){
        	if((parseInt($('.like-red111')[1].innerHTML)+2)>20000){
        		$('#msg_content').html('每次购买不能超过20000金额');
        		start_dialog2('err_msg',2,'print_ok_time');
        		return;
        		$(this).attr('class','icon-white');
        	}	
        	else{
            	var max_money = 2*self.compute_amount();
                if($(this).attr('class') == 'icon-white1'){
                		$(this).attr('class','icon-'+color+'-1');
                		if (2*self.compute_amount() > 20000){
                			$(this).attr('class','icon-white1');
                			var ti = self.compute_amount();
                            if(ti>-1){
                                $('.like-red')[0].innerHTML = ti;
                                $('.like-red')[1].innerHTML = ti * 2;
                            }
                			$('#msg_content').html('每次购买不能超过20000金额');
                    		start_dialog2('err_msg',2,'print_ok_time');
                    		return;
                		}       
                }
                else{
                	
                    $(this).attr('class','icon-white1');
                }

            	} 
        	var ti = self.compute_amount();
            if(ti>-1){
                $('.like-red')[0].innerHTML = ti;
                $('.like-red')[1].innerHTML = ti * 2;
            }
        });
        $('.'+color+'_select > i.icon-white').click(function(e){
        	if((parseInt($('.like-red111')[1].innerHTML)+2)>20000){
        		$('#msg_content').html('每次购买不能超过20000金额');
        		start_dialog2('err_msg',2,'print_ok_time');
        		return;
        		$(this).attr('class','icon-white');
        	}
        	else{
        	var num = self.get_balls('.red_select > i.icon-red').length;
        	var max_money = 2*self.compute_amount();
            if($(this).attr('class') == 'icon-white'){
            	if (color == 'red'){
            	if (num < self.redmax){
            		$(this).attr('class','icon-'+color);
            		if (2*self.compute_amount() > 20000){
            			$(this).attr('class','icon-white');
            			var ti = self.compute_amount();
                        if(ti>-1){
                            $('.like-red')[0].innerHTML = ti;
                            $('.like-red')[1].innerHTML = ti * 2;
                        }
            			$('#msg_content').html('每次购买不能超过20000金额');
                		start_dialog2('err_msg',2,'print_ok_time');
                		return;
            		}
            	}
            	else{
            		var ma = self.redmax;
            		$('#msg_content').html('最多只能选择'+ma+'个红球');
            		start_dialog2('err_msg',2,'print_ok_time');
            		return;
            	}
            	}
            	else{
            		
            		$(this).attr('class','icon-'+color);
            		if (2*self.compute_amount() > 20000){
            			$(this).attr('class','icon-white');
            			var ti = self.compute_amount();
                        if(ti>-1){
                            $('.like-red')[0].innerHTML = ti;
                            $('.like-red')[1].innerHTML = ti * 2;
                        }
            			$('#msg_content').html('每次购买不能超过20000金额');
                		start_dialog2('err_msg',2,'print_ok_time');
                		return;
            		}
            	}
            }else{
            	
                $(this).attr('class','icon-white');
            }
        	}   
            var ti = self.compute_amount();
            if(ti>-1){
                $('.like-red')[0].innerHTML = ti;
                $('.like-red')[1].innerHTML = ti * 2;
            }	
        });
        }
    },
    randone : function(){

        var balls = this.randballs(this.redrequire,this.rednummax,this.redmin);
        if(this.bluerequire != -1){
            balls = balls.concat(this.randballs(this.bluerequire,this.bluenummax,this.redmin));  //默认蓝球最小数字和红球一样，这里用redmin
        }
        if(this.sxrequire == 1){
            balls = balls.concat(this.randballs(this.sxrequire,this.sxnummax,this.redmin));  
        }
        if(this.needzero){
            //个位数前面补0，保持对齐
            for(var i=0;i<balls.length;i++){
                if(balls[i]<10){
                    balls[i] = "0"+balls[i];
                }
            }
        }
        var randnum = balls.toString();
        var randnum1 = randnum;
        //如果有蓝球
        if(this.bluerequire != -1){
            var blue = balls.pop();

            randnum = balls.toString()+"|"+blue;
            var randnum1 = randnum;
        }
        if(this.sxrequire == 1){
            var sx = balls.pop();
            var sx1 = true;
            switch(sx)
            {
         
               case 1:
            	   sx1 = "鼠"
                 break;
               case 2:
            	   sx1 = "牛"
                 break;
               case 3:
            	   sx1 = "虎"
                 break;
               case 4:
            	   sx1 = "兔"
                 break;
               case 5:
            	   sx1 = "龙"
                 break;
               case 6:
            	   sx1 = "蛇"
                 break;
               case 7:
            	   sx1 = "马"
                 break;
               case 8:
            	   sx1 = "羊"
                 break;
               case 9:
            	   sx1 = "猴"
                 break;
               case 10:
            	   sx1 = "鸡"
                 break;
               case 11:
            	   sx1 = "狗"
                 break;
               case 12:
            	   sx1 = "猪"
                 break;
            }
            randnum = balls.toString()+"|"+sx;
            randnum1 = balls.toString()+"|"+sx1;
        }
        if ($('#num_pool option:selected').val() == undefined){
        	$('.select-list').append("<option value='{0}#".format(randnum)+this.fangshi+"#1#1#2' selected='selected' >{0}</option>".format(this.formater.format(randnum1,1,2)));
        }
        else{
        	$('.select-list').append("<option value='{0}#".format(randnum)+this.fangshi+"#1#1#2' >{0}</option>".format(this.formater.format(randnum1,1,2)));
        }
    },

    get_lottery_object : function(){
        var value = this.redballs.toString();
        var num = this.count;
        if(this.bluerequire != -1){
            value += "|"+this.blueballs.toString();
            num = num * this.blueballs.length; //总注数
        }
        if(this.bluerequire == -1 && this.type == '20'){
            value = this.redballs.join('');
        }
        var wanfa = num>1?'2':'1';//1-单注,2-复式
        var fangshi = this.fangshi;
        return new object(this.formater,value,value,num,fangshi,wanfa,1);
    },
    //获取总金额的唯一入口，投注信息在添加到select list后js状态即重置了，
    //所以总的投注金额必须通过select list来获取
    get_pay_num : function(){
        var nums = [];
        $('.select-list option').each(function(){
            var ll = $(this).attr('value').split('#');
            nums.push(ll[ll.length-1]);
        });
        //return eval(nums.join("+"))
        return eval(nums.join("+")) * parseInt($('.sb_number').html()); //求和
    },

    start_dialog : function(id,autocount,countid,callback){
        callback = callback || function(){};
        autocount = autocount || 0;
        countid = countid || null;
        easyDialog.close();
        easyDialog.open({
            container : id,
                fixed : true,
                callback: callback,
                autocount : autocount,  //开启倒计时
                countid : countid
        });
    },
    saixuanclickevent : function (ws,cc){
        var self = this;
        $('.'+ws+'> b.icon-z-'+cc).click(function(e){	
        	if (cc == "quan"){
        		$('.'+ws+' > i.icon-white').attr('class','icon-red');	
        	}
        	if (cc == "da"){
        		for (var j=5;j<10;j=j+1){
        			$('.'+ws+' i:contains('+j+')').attr('class','icon-red');
        		}
        		for (var t=0;t<5;t=t+1){
        			$('.'+ws+' i:contains('+t+')').attr('class','icon-white');
        		}
        	}
        	if (cc == "xiao"){
        		for (var j=5;j<10;j=j+1){
        			$('.'+ws+' i:contains('+j+')').attr('class','icon-white');
        		}
        		for (var t=0;t<5;t=t+1){
        			$('.'+ws+' i:contains('+t+')').attr('class','icon-red');
        		}
        	}
        	if (cc == "ji"){
        		for (var j=1;j<10;j=j+2){
        			$('.'+ws+' i:contains('+j+')').attr('class','icon-red');
        		}
        		for (var t=0;t<10;t=t+2){
        			$('.'+ws+' i:contains('+t+')').attr('class','icon-white');
        		}
        	}
        	if (cc == "ou"){
        		for (var j=1;j<10;j=j+2){
        			$('.'+ws+' i:contains('+j+')').attr('class','icon-white');
        		}
        		for (var t=0;t<10;t=t+2){
        			$('.'+ws+' i:contains('+t+')').attr('class','icon-red');
        		}
        	}
        	if (cc == "del"){
        		$('.'+ws+' > i.icon-red').attr('class','icon-white');	
        	}
        	if (2*self.compute_amount() > 20000){
    			$('.'+ws+' > i.icon-red').attr('class','icon-white');	
    			var ti = self.compute_amount();
                if(ti>-1){
                    $('.like-red')[0].innerHTML = ti;
                    $('.like-red')[1].innerHTML = ti * 2;
                }
    			$('#msg_content').html('每次购买不能超过20000金额');
        		start_dialog2('err_msg',2,'print_ok_time');
        		return;
    		}
        	var ti = self.compute_amount();
            if(ti>-1){
                $('.like-red')[0].innerHTML = ti;
                $('.like-red')[1].innerHTML = ti * 2;
            }
        });
    },
    validate : function(lo){
        if(this.redballs.length>this.redmax){
            $('#msg_content').html('最多只能选择'+this.redmax+'个红球');
            start_dialog2('err_msg',2,'print_ok_time');
            return;
        }
        if(this.redballs.length<this.redrequire){
            $('#msg_content').html('请至少选择'+this.redrequire+'个红球!');
            start_dialog2('err_msg',2,'print_ok_time');
            return;
        }
        if(this.bluerequire != -1&&this.blueballs.length<this.bluerequire){
        	$('#msg_content').html('请至少选择'+this.bluerequire+'个蓝球!');
            start_dialog2('err_msg',2,'print_ok_time');
            return;
        }

        if(lo.num*2>this.buymax){
            $('#msg_content').html('单注金额最高'+this.buymax+'元');
            start_dialog2('err_msg',2,'print_ok_time');
            return;
        }
        return true;
    },
    init_events : function(){
        var self = this;
        var a = ["gewei","shiwei","baiwei","qianwei","wanwei"];
        var b = ["quan","da","xiao","ji","ou","del"];
        for (var i=0;i<a.length;i=i+1){
            if(this.bluerequire != -1){
            	this.ballclickevent(a[i],'blue');
            }
            this.ballclickevent(a[i],'red');
        } 
        for (var i=0;i<a.length;i=i+1){
        	for(var j=0;j<b.length;j=j+1){
        		this.saixuanclickevent(a[i],b[j]);
        	}
        }
        //机选1注按钮
        $('#c1').click(function(){
        	var t = parseInt($('.sb_number').html());
        	if((parseInt($('.like-red111')[1].innerHTML)+2*t)>20000){
        		$('#msg_content').html('每次购买不能超过20000金额');
        		start_dialog2('err_msg',2,'print_ok_time');
        		return;
        	}
        	else{
        		self.randone();
        		var sum_money = 0;
                var mulriple = parseInt($('.sb_number').html());
                $("#num_pool option").each(function () {
        			var tex = $(this).text();
        			var val = $(this).val();
        			sum_money = sum_money+parseInt(val.split("#")[4]);
                });
                $('.like-red111')[0].innerHTML = sum_money/2*mulriple;
                $('.like-red111')[1].innerHTML = sum_money*mulriple;
        	}
        	
        });

        //机选5注按钮
        $('#c5').click(function(){
        	var t = parseInt($('.sb_number').html());
        	if((parseInt($('.like-red111')[1].innerHTML)+10*t)>20000){
        		$('#msg_content').html('每次购买不能超过20000金额');
        		start_dialog2('err_msg',2,'print_ok_time');
        		return;
        	}
        	else{
            for(var i=0;i<5;i++){
                self.randone();
            }}
        	var sum_money = 0;
            var mulriple = parseInt($('.sb_number').html());
            $("#num_pool option").each(function () {
    			var tex = $(this).text();
    			var val = $(this).val();
    			sum_money = sum_money+parseInt(val.split("#")[4]);
            });
            $('.like-red111')[0].innerHTML = sum_money/2*mulriple;
            $('.like-red111')[1].innerHTML = sum_money*mulriple;
        });

        //列表删除按钮
        $('#del').click(function(){
        	if ($('.select-list option:selected').val()==undefined){
        		$('.select-list option:last').remove();
        	}
        	else
    		{
    			$('.select-list option:selected').remove();
    		}
        	if ($('#num_pool option:selected').val() == undefined){
        		var t =$('#num_pool option:first').index();
        		$('#num_pool').get(0).selectedIndex=t;
        	}

        	var sum_money = 0;
            var mulriple = parseInt($('.sb_number').html());
            $("#num_pool option").each(function () {
    			var tex = $(this).text();
    			var val = $(this).val();
    			sum_money = sum_money+parseInt(val.split("#")[4]);
            });
            $('.like-red111')[0].innerHTML = sum_money/2*mulriple;
            $('.like-red111')[1].innerHTML = sum_money*mulriple;
            var mulriple = parseInt($('.sb_number').html());
            if (parseInt($('.like-red111')[1].innerHTML) == 0){
            	$('.sb_number').html(1);
            }
        });

        //列表清空按钮
        $('#reset').click(function(){
            $('.select-list').html('');
            var sum_money = 0;
            $("#num_pool option").each(function () {
    			var tex = $(this).text();
    			var val = $(this).val();
    			sum_money = sum_money+parseInt(val.split("#")[4]);
            });
            $('.like-red111')[0].innerHTML = sum_money/2;
            $('.like-red111')[1].innerHTML = sum_money;
            var mulriple = parseInt($('.sb_number').html());
            if (parseInt($('.like-red111')[1].innerHTML) == 0){
            	$('.sb_number').html(1);
            }
        });

        //"添加到选号列表"按钮
        $('#add_num').click(function(){
            var lo = self.get_lottery_object();
            var max_money = 2*self.compute_amount();
            var mul = parseInt($('.sb_number').html());
            if (max_money*mul+parseInt($('.like-red111')[1].innerHTML) > 20000){
            	$('#msg_content').html('每次购买不能超过20000金额');
        		start_dialog2('err_msg',2,'print_ok_time');
        		return;
        	}
            else{
	            if(self.validate(lo)){
	                if ($('#num_pool option:selected').val() == undefined){
	                	$('.select-list').append("<option value='{0}' selected='selected'>{1}</option>".format(lo.value,lo.get_desc()));
	                }
	                else{
	                	$('.select-list').append("<option value='{0}' >{1}</option>".format(lo.value,lo.get_desc()));
	                }
	                self.reset();
	            }
	            var sum_money = 0;
	            var mulriple = parseInt($('.sb_number').html());
	            $("#num_pool option").each(function () {
	    			var tex = $(this).text();
	    			var val = $(this).val();
	    			sum_money = sum_money+parseInt(val.split("#")[4]);
	            });
	            $('.like-red111')[0].innerHTML = sum_money/2*mulriple;
	            $('.like-red111')[1].innerHTML = sum_money*mulriple;
            }
            
        });
        //倍投减
        $('.sb_sub').click(function(){
            var mulriple = parseInt($('.sb_number').html());
            if (parseInt($('.like-red111')[1].innerHTML) == 0){
            	$('.sb_number').html(1);
            }
            else{
            	if(mulriple > 1){
            		var sum_money = 0;
                    $("#num_pool option").each(function () {
            			var val = $(this).val();
            			sum_money = sum_money+parseInt(val.split("#")[4]);
                    });
                    
            		$('.sb_number').html(mulriple-1);
            		$('.like-red111')[0].innerHTML = sum_money/2*(mulriple-1);
                    $('.like-red111')[1].innerHTML = sum_money*(mulriple-1);
            }
            
            }
        });

        //倍投加
        $('.sb_add').click(function(){
            var mulriple = parseInt($('.sb_number').html());
            if (parseInt($('.like-red111')[1].innerHTML) == 0){
            	$('.sb_number').html(1);
            }
            else{
            	var max_num = 50;
            	var header_id = $('.header').attr('id');
            	if(header_id=='header_ssc'){
            		max_num = 99;
            	}
            	
            	if(mulriple < max_num){
        			var sum_money = 0;
                    $("#num_pool option").each(function () {
            			var val = $(this).val();
            			sum_money = sum_money+parseInt(val.split("#")[4]);
                    });
                    if (sum_money*(mulriple+1) > 20000){
                    	$('#msg_content').html('每次购买不能超过20000金额');
                		start_dialog2('err_msg',2,'print_ok_time');
                		return;
                    }
                    else{
                    	$('.sb_number').html(mulriple+1);
                		$('.like-red111')[0].innerHTML = sum_money/2*(mulriple+1);
                        $('.like-red111')[1].innerHTML = sum_money*(mulriple+1);
                    }
            	}
            }
            
        });

        //立即投注按钮
        $('#buylottery').click(function(){
            if($('.select-list option').length==0){
            	$('#msg_content').html('至少选择1注号码才能投注');
            	self.start_dialog('err_msg',2,'print_ok_time');
                return;
            }
            var lvalue = [];
            beishu = parseInt($('.sb_number').html())
            $('.select-list option').each(function(){
            	values = $(this).val().split("#")
            	value = values[0]+"#"+values[1]+"#"+values[2]+"#"+beishu+"#"+beishu*parseInt(values[4])
                lvalue.push(value);
            });
            $.ajax({
                type:'POST',
                url:'/chk_buy_lottery',
                data:{
                	periodid:$('#period').html(),
                    lotterys:lvalue,
                    type:self.type,
                    mac:pyObj.get_if_mac()
                },
                success:function(data,status){
                	$('.toubi_geshu_in').html('0');
                    easyDialog.open({
                        container : 'pay_type',
                        autoClose : 0,
                        fixed : true
                    });
                },
                error:function (req, status, error){
                	$('#msg_content').html(req.responseText);
                	self.start_dialog('err_msg',2,'print_ok_time');
                },
            });
        });
       
        $('#bank_code').blur(function(){
        	if($("#bank_num").html()==''){
        		$('#bank_code').focus();
        	}
        });
        //刷卡购按钮
        $('#select_shuka').click(function(){
        	$('#bank_num').html("");
        	$('#bank_code').val('');
        	
        	self.start_dialog('shuka_pay',120,'shuka_time');
        	var pay_num = self.get_pay_num();
        	$('#pay_money').html(pay_num);
            $('#bank_code').focus();
        });
        
        $('#bank_code').bind('input',function(){
        	value=$(this).val();
	    	if(value.length>38){
	    		if(value.indexOf(';')!=-1 && value.indexOf('?')!=-1){
	    			index = value.indexOf(";");
	    			indexD = value.indexOf("=");
		    		value = value.substring(1,index+5)+"**********"+value.substring(indexD-3,indexD);
		    		$("#bank_num").html(value);
	    		}else{
	    			$('#msg_content').html('磁条卡错误，请检查是否消磁');
	    			self.start_dialog('err_msg',5,'print_ok_time');
                	$('#bank_code').val('');
                	$('#bank_code').focus();
	    		}
	    	}else if(value.indexOf(';')!=-1 && value.indexOf('?')!=-1){
	    		$('#msg_content').html("非磁条卡输入");
            	self.start_dialog('err_msg',5,'print_ok_time');
            	$('#bank_code').val('');
            	$('#bank_code').focus();
	    	}
        });
        
        //刷卡完成，进入下一步，输入密码
        $('#shuaka_next1').click(function(){
        	var pay_num = self.get_pay_num();
        	$('.pay_num').html(pay_num);
        	$('#bank_num').val('');
        	$('#shuka_password').val('');
        	self.start_dialog('inputpwd_pay',12,'inputpwd_time');
        	result=pyObj.input_bank_password($('#bank_code').val());
        });
        
        //投币购买按钮
        $('#select_toubi').click(function(){
            var pay_num = self.get_pay_num();
            $('.pay_num').html(pay_num);
            has_coin = pyObj.get_coin();
            $('.toubi_geshu_in').html(has_coin);
            self.start_dialog('toubi_pay',180,'time');
            pyObj.start_take_coin(pay_num);           
        });

        $('#card_code').blur(function(){
        	if($('#pricecard').val()==''){
        		$('#card_code').focus();
        	}
        });
        //人工代购按钮
        $('#select_daigou').click(function(){
            var pay_num = self.get_pay_num();
            $('.pay_num').html(pay_num);
            self.start_dialog('daigou_pay',100,'daigou_time');
            $('#password').val('');
            $('#card_code').focus();
            $('#card_code').val('');
            $('.input_keybord').hide();
            $('#card_code').bind('input',function(){
            	cardnumber = $('#card_code').val();
            	if(cardnumber.length>9){
            		$('#pricecard').val(cardnumber.slice(1,9));
            		$('.input_keybord').show();
            	}
            });
        });

        //软键盘数字键
        $('i.bottom').click(function(){
            //console.log($(this).children().html());
            $('#password').val($('#password').val()+$(this).children().html());
        });

      //软键盘数字键
        $('i.bottom').click(function(){
            //console.log($(this).children().html());
            $('#shuka_password').val($('#shuka_password').val()+$(this).children().html());
        });
        
        
        //软键盘删除键
        $('i.dele').click(function(){
            var c = $('#password').val();
            $('#password').val(c.slice(0,c.length-1));
        });
        
      //软键盘删除键
        $('i.dele').click(function(){
            var c = $('#shuka_password').val();
            $('#shuka_password').val(c.slice(0,c.length-1));
        });

        //软键盘清空键
        $('i.rest').click(function(){
           $('#password').val(''); 
        });
        
      //软键盘清空键
        $('i.rest').click(function(){
           $('#shuka_password').val(''); 
        });

        //代购确定按钮
        $('#daigou_ok').click(function(){
            self.buy_lottery(2,function(){
                $('.input_keybord').hide();
                $('#password').val(''); 
                $('#pricecard').val('');
                $('#card_code').val('');
           });
        });   
        
      //shuka确定按钮
        $('#shuka_ok').click(function(){
            self.buy_lottery(2,function(){
            	$('.input_keybord').hide();
                $('#shuka_password').val('');
            });
        });
       
        $('.close').click(function(){
                // $('#shuka_password').val(''); 
                 easyDialog.close();
        });
        $('#daigou_close').click(function(){
            $('#password').val(''); 
            $('#pricecard').val('');
            easyDialog.close();
       });
        //密码输入框
        //$('#password').click(function(){$('#daigou_password').show();})
        //$('#shuka_password').click(function(){$('#shuka_input_key').show();})
        //$('#password').blur(function(){$('.input_keybord').hide();})
        // $('#pricecard').blur(function(){$('#daigou_password').show();});
        // $('#pricecard').focus(function(){$('.input_keybord').hide();});
        //$('#password').focus(function(){$('.input_keybord').show();});
        //$('#password').blur(function(){$('.input_keybord').hide();});
        
        //刷卡后自动跳到输密码
        $('#pricecard').change(function(){
        	if($(this).val().length==8){
        		$('#password').focus();
        	}
        });
    },
    buy_lottery : function(buymethod,complete){
        complete = complete || function(){};
        beishu = parseInt($('.sb_number').html())
        var self = this;
        var lvalue = [];
        $('.select-list option').each(function(){
            //lvalue.push($(this).val());
        	values = $(this).val().split("#")
        	value = values[0]+"#"+values[1]+"#"+values[2]+"#"+beishu+"#"+beishu*parseInt(values[4])
            lvalue.push(value);
        });

        $.ajax({
            type:'POST',
            //dataType:'json',
            url:'/buy_lottery',
            data:{
                lotterys:lvalue,
                type:self.type,
                mac:pyObj.get_if_mac(),
                buymethod : buymethod,  //#购买方式，刷卡，投币或代购
                prizeType : 0,  //#现金:0,银联：1
                periodid : $('#period').html(),
                pricecard: $('#pricecard').val(),
                password:  $('#password').val()
            },
            beforeSend:function (req) {
               self.start_dialog('print_ti');
            },
            success:function(data,status){
            	obj = eval("(" + data + ")");
                result=pyObj.print_lottery(self.type,data);
                if(!result){
                	$('#msg_content').html("打印彩票失败");
                	self.start_dialog('err_msg',2,'print_ok_time');
                	if(buymethod==0){ //刷卡消费，冲正
                		pyObj.yeepay_rollback();
                	}
                	$.ajax({
                		type:'POST',
                		url:'/trade_pos_fail',
                		dataType:'json',
                		data:{sd_batchid:obj['sd_batchid']},
                		success:function(data,status){},
                		error:function(req,status,error){}
                	});
                }else{
                	self.start_dialog('print_ok',15,'print_ok_time',function(){
                        self.reset();
                        $('.select-list').html('');
                        $('.like-red111')[0].innerHTML = 0;
                        $('.like-red111')[1].innerHTML = 0;
                        $('.sb_number').html(1);
                    });
                }
            },
            error:function (req, status, error){
            	$('#msg_content').html(req.responseText);
            	self.start_dialog('err_msg',2,'print_ok_time');
            	if(buymethod==0){ //刷卡消费，冲正
            		pyObj.yeepay_rollback();
            	}
            },
            complete:complete
        });
    },
    init_updater : function(msercond){
        var update = function(){
            $.ajax({
                type:'POST',
                url:'/period',
                dataType:'json',
                data:{
                    type:lottery.type
                },
                success:function(data,status){
                    $('#period').html(data['periodid']);
                    $('#enddate').html(data['enddate']);
                    setTimeout(update,data['msercond']*1000);
                    //if(data['#enddate']=='开奖中...'){
                    //	$('#enddate').html(data['enddate']);
                   // }else{
                   // 	$("#enddate").countDown(data['msercond']);
                   // }
                },
                error:function (req, status, error){
                    setTimeout(update,5000);  //失败5秒重试
                }
            });
        };
        setTimeout(update,msercond*1000);
       // $("#enddate").countDown(msercond);
    }
});

$.fn.extend({
	countDown : function(seconds) {
		var $this = $(this);	
		var day,hour,minute,second;		
		var timer = setInterval(function(){
			seconds -= 1;
			if (seconds >= 0) {
				day = Math.floor((seconds / 3600) / 24);	
				hour = Math.floor((seconds / 3600) % 24);
				minute = Math.floor((seconds / 60) % 60);
				second = Math.floor(seconds % 60);
				day = day+"天"
				hour = (hour<10?"0"+hour:hour)+"时 ";//计算小时
				minute = (minute<10?"0"+minute:minute)+"分 ";//计算分
				second = (second<10?"0"+second:second)+"秒";// 计算秒
				$this.text(day+hour+minute+second);
			} else { 
				clearInterval(timer);
			}
		}, 1000);
	}
})

var xingshi = mathine.$extend({
    __init__ : function(args){
        this.$super(args);
        this.unit = args.unit;
        this.gewei = [];
        this.shiwei = [];
        this.baiwei = [];
        this.qianwei = [];
        this.wanwei = [];
        this.san = [];
        this.liu = [];
    },
    validate : function(lo){
        var vali = true;
        switch(this.unit)
        {
           case 2:
             vali = this.gewei.length<1||this.shiwei.length<1;
             break;
           case 3:
             vali = this.gewei.length<1||this.shiwei.length<1||this.baiwei.length<1;
             break;
           case 4:
             vali = this.gewei.length<1||this.shiwei.length<1||this.baiwei.length<1||this.qianwei.length<1;
             break;
           case 5:
               vali = this.san.length<this.redrequire;
               break;
           case 6:
               vali = this.liu.length<this.redrequire;
               break;
           case 7:
               vali = this.gewei.length<1||this.shiwei.length<1||this.baiwei.length<1||this.qianwei.length<1||this.wanwei.length<1;
               break;
           case 22:
               vali = this.gewei.length<2;
               break;
           case 31:  
               vali = this.gewei.length!=1||this.shiwei.length!=1||this.baiwei.length!=1;
               var g = String(this.gewei);
               var s = String(this.shiwei);
               var b = String(this.baiwei);
               vali1 = !(((g == s) && (s != b))||((g == b) && (b != s))||((s == b) && (b != g)));
               break;
           case 32:
               vali = this.gewei.length<3;
               break;
           case 71:
               vali = this.gewei.length<1||this.shiwei.length<1||this.baiwei.length<1||this.qianwei.length<1||this.wanwei.length<1;
               break;
           case 8:
               vali = this.gewei.length!=1||this.shiwei.length!=1;
               
               break;
           case 311:
               vali = this.gewei.length<this.redrequire;
               break;
        }
        if(this.unit == 31 && vali1){
            	$('#msg_content').html('组3由2个数字组成，其中一个数字出现2次');
            	self.start_dialog2('err_msg',2,'print_ok_time');
                return false;
        	 }
        if(vali){
        	if (this.unit == 5 || this.unit == 6 || this.unit == 22 || this.unit == 22 || this.unit == 311){
        		
        		$('#msg_content').html('至少选择'+this.redrequire+'个号码球');
            	self.start_dialog2('err_msg',2,'print_ok_time');
                return false;
        	}
        	else{
        		$('#msg_content').html('每位至少选择1个号码球');
            	self.start_dialog2('err_msg',2,'print_ok_time');
                return false;
        	}
        	
        }
        return true;
    },
 
    get_html_with_unit : function (){
        switch(this.unit)
        {
           
           case 2:
             return this.shiwei.join('') + "," + this.gewei.join('');
           case 3:
             return this.baiwei.join('') + "," + this.shiwei.join('') + "," + this.gewei.join('');
           case 4:
             return this.qianwei.join('') + "," + this.baiwei.join('') + "," + this.shiwei.join('') + "," + this.gewei.join('');
           case 5:
        	   return this.san.join(',');
           case 6:
        	   return this.liu.join(',');
           case 22:
               return this.gewei.join(',') ;
           case 31:
               return this.baiwei.join('') + "," + this.shiwei.join('') + "," + this.gewei.join('');
           case 7:
               return this.wanwei.join('') + "," + this.qianwei.join('') + "," + this.baiwei.join('') + "," + this.shiwei.join('') + "," + this.gewei.join('');
           case 32:
               return this.gewei.join(',') ;
           case 71:
               return this.wanwei.join('') + "," + this.qianwei.join('') + "," + this.baiwei.join('') + "," + this.shiwei.join('') + "," + this.gewei.join('');
           case 8:
               return this.shiwei.join('') + "|" + this.gewei.join('');
           case 311:
        	   return this.gewei.join(',');
           default:
             return "";
        }
    },
    get_value_with_unit : function (){
        switch(this.unit)
        {
           case 2:
             return this.shiwei.join('')+","+this.gewei.join('');
           case 3:
             return this.baiwei.join('')+","+this.shiwei.join('')+","+this.gewei.join('');
           case 4:
             return this.qianwei.join('')+","+this.baiwei.join('')+","+this.shiwei.join('')+","+this.gewei.join('');
           case 5:
        	   return this.san.join(',');
           case 6:
        	   return this.liu.join(',');
           case 22:
               return this.gewei.join(',') ;
           case 31:
               return this.baiwei.join('') + "," + this.shiwei.join('') + "," + this.gewei.join('');
           case 7:
        	   return this.wanwei.join('') + "," + this.qianwei.join('') + "," + this.baiwei.join('') + "," + this.shiwei.join('') + "," + this.gewei.join('');
           case 32:
               return this.gewei.join(',') ;
           case 71:
        	   return this.wanwei.join('') + "," + this.qianwei.join('') + "," + this.baiwei.join('') + "," + this.shiwei.join('') + "," + this.gewei.join('');
           case 8:
               return this.shiwei.join('') + "," + this.gewei.join('');
           case 311:
        	   return this.gewei.join(',');
           default:
             return "";

        }
      
    },
    get_lottery_object : function(){
        var html = this.get_html_with_unit(); //列表显示
        var value = this.get_value_with_unit(); //传到后台的值
        var num = this.count;
        if (this.unit == 22 || this.unit == 311 || this.unit == 32 || this.unit == 5|| this.unit == 6){
        	var wanfa = num>1?'3':'1';//1-单注,3-包号
        }
        else{
        	var wanfa = num>1?'2':'1';//1-单注,2-复式
        }
        var fangshi = this.fangshi;
        return new object(this.formater,value,html,num,fangshi,wanfa,1);
    },
  
    selectball : function(){
        this.gewei = this.get_balls('.gewei > i.icon-red');
        this.shiwei = this.get_balls('.shiwei > i.icon-red');
        this.baiwei = this.get_balls('.baiwei > i.icon-red');
        this.qianwei = this.get_balls('.qianwei > i.icon-red');
        this.wanwei = this.get_balls('.wanwei > i.icon-red');
        this.san = this.get_balls('.san > i.icon-red');
        this.liu = this.get_balls('.liu > i.icon-red');
        
        switch(this.unit)
        {
           case 2:
                this.count = this.gewei.length * this.shiwei.length;
                return this.gewei.length>0&&this.shiwei.length>0;  //至少满足一注
           case 3:
                this.count = this.gewei.length * this.shiwei.length * this.baiwei.length;
                return this.gewei.length>0&&this.shiwei.length>0&&this.baiwei.length>0;  //至少满足一注
           case 4:
                this.count = this.gewei.length * this.shiwei.length * this.baiwei.length * this.qianwei.length;
                return this.gewei.length>0&&this.shiwei.length>0&&this.baiwei.length>0&&this.qianwei.length>0;  //至少满足一注
           case 5:
        	   this.count = this.san.length>=this.redrequire ? this.C(this.san,this.redrequire)*2:0;
               return this.san.length>=this.redrequire;
           case 6:
        	   this.count = this.liu.length>=this.redrequire ? this.C(this.liu,this.redrequire):0;
               return this.liu.length>=this.redrequire;
           case 22:
        	   var s = this.gewei.length<2 ? 0:1;
        	   this.count = this.gewei.length>2 ? (this.C(this.gewei,this.redrequire)+this.gewei.length):s;
        	   return this.gewei.length>=2; //至少满足一注
           case 31:
               this.count = this.gewei.length * this.shiwei.length * this.baiwei.length;
               var g = String(this.gewei);
               var s = String(this.shiwei);
               var b = String(this.baiwei);
               if ((g == s && s != b)||(g == b && b != s)||(b == s && s != g)){
               return this.gewei.length>0&&this.shiwei.length>0&&this.baiwei.length>0;
               }
           case 7:
               this.count = this.gewei.length * this.shiwei.length * this.baiwei.length * this.qianwei.length* this.wanwei.length;
               return this.gewei.length>0&&this.shiwei.length>0&&this.baiwei.length>0&&this.qianwei.length>0&&this.wanwei.length>0;  //至少满足一注
           case 32:
        	   this.count = this.gewei.length>=this.redrequire ? this.C(this.gewei,this.redrequire):0;
               return this.gewei.length>=this.redrequire;
           case 71:
               this.count = this.gewei.length * this.shiwei.length * this.baiwei.length * this.qianwei.length* this.wanwei.length;
               return this.gewei.length>0&&this.shiwei.length>0&&this.baiwei.length>0&&this.qianwei.length>0&&this.wanwei.length>0;  //至少满足一注
           case 8:
               this.count = this.gewei.length * this.shiwei.length;
               return this.gewei.length>0&&this.shiwei.length>0;  //至少满足一注
           case 311:
        	   this.count = this.gewei.length>=this.redrequire ? this.C(this.gewei,this.redrequire)*2:0;
               return this.gewei.length>=this.redrequire;
           default:
             return false;
        }
       
    }
});


var dantuo = mathine.$extend({
    __init__ : function(args){
    	this.$super(args);
        this.tuonummax = args.tuonummax;  
        this.dannummax = args.dannummax;  
        this.tuomin = args.tuomin;
        this.danmin = args.danmin;
        this.tuoballs = [];
        this.danballs = [];
        this.blueballs = [];
        this.tuomax = args.tuomax; 
        this.danmax = args.danmax; 
    },
    selectball : function(){
        this.tuoballs = this.get_balls('.tuoma > i.icon-red');
        this.danballs = this.get_balls('.danma > i.icon-red');
        
        if(this.bluerequire != -1){
        	
        	this.count = this.danballs.length>=this.danmin ? ((this.tuoballs.length+this.danballs.length)>=this.redrequire ? this.C(this.tuoballs,(6-this.danballs.length)):1):0;
            this.blueballs = this.get_balls('.blue_select > i.icon-blue');    
        }
        else{  	
        	this.count = this.count = this.danballs.length>=this.danmin ? ((this.tuoballs.length+this.danballs.length)>=this.redrequire ? this.C(this.tuoballs,(this.redrequire-this.danballs.length)):1):0;
        }   
        return (this.tuoballs.length+this.danballs.length)>=this.redrequire&&this.blueballs.length>=this.bluerequire;  //至少满足一注
    },
    ballclickevent : function (wei,color){
        var self = this;
        $('.'+color+'_select > i.icon-white').click(function(e){
        	if((parseInt($('.like-red111')[1].innerHTML)+2)>20000){
        		$('#msg_content').html('每次购买不能超过20000金额');
        		start_dialog2('err_msg',2,'print_ok_time');
        		return;
        	}
        	else{
        	var tnum = self.get_balls('.tuoma > i.icon-red').length;
        	var dnum = self.get_balls('.danma > i.icon-red').length;
        	var max_money = 2*self.compute_amount();
            if($(this).attr('class') == 'icon-white' ){
            	if (color == 'red'){
            	if ($(this).attr('name') == 'tm')	{
            	if (tnum < self.tuomax){ 
            		$(this).attr('class','icon-'+color);
            		var th = String($(this).html());
            		$(".danma i:contains('" + th + "')").attr('class','icon-white');
            		if (2*self.compute_amount() > 20000){
            			$(this).attr('class','icon-white');
            			var ti = self.compute_amount();
                        if(ti>-1){
                            $('.like-red')[0].innerHTML = ti;
                            $('.like-red')[1].innerHTML = ti * 2;
                        }
            			$('#msg_content').html('每次购买不能超过20000金额');
                		start_dialog2('err_msg',2,'print_ok_time');
                		return;
            		}
               
            	}
            	else{
            		$('#msg_content').html('最多只能选择'+self.tuomax+'个拖码');
            		start_dialog2('err_msg',2,'print_ok_time');
            		return;
            	}
            	}
            	if ($(this).attr('name') == 'dm')	{
            
            	if (dnum < self.danmax){
            		$(this).attr('class','icon-'+color);
            		var tz = String($(this).html());
            		$(".tuoma i:contains('" + tz + "')").attr('class','icon-white');
            		if (2*self.compute_amount() > 20000){
            			$(this).attr('class','icon-white');
            			var ti = self.compute_amount();
                        if(ti>-1){
                            $('.like-red')[0].innerHTML = ti;
                            $('.like-red')[1].innerHTML = ti * 2;
                        }
            			$('#msg_content').html('每次购买不能超过20000金额');
                		start_dialog2('err_msg',2,'print_ok_time');
                		return;
            		}
               
            	}
            	else{
            		$('#msg_content').html('最多只能选择'+self.danmax+'个胆码');
            		start_dialog2('err_msg',2,'print_ok_time');
            		return;
            	}
            	}
            	}
            	else{
            		$(this).attr('class','icon-'+color);
            		if (2*self.compute_amount() > 20000){
            			$(this).attr('class','icon-white');
            			var ti = self.compute_amount();
                        if(ti>-1){
                            $('.like-red')[0].innerHTML = ti;
                            $('.like-red')[1].innerHTML = ti * 2;
                        }
            			$('#msg_content').html('每次购买不能超过20000金额');
                		start_dialog2('err_msg',2,'print_ok_time');
                		return;
            		}
            		
            	}
            }else{
                $(this).attr('class','icon-white');
                if (2*self.compute_amount() > 20000){
                	$(this).attr('class','icon-'+color);
        			var ti = self.compute_amount();
                    if(ti>-1){
                        $('.like-red')[0].innerHTML = ti;
                        $('.like-red')[1].innerHTML = ti * 2;
                    }
        			$('#msg_content').html('每次购买不能超过20000金额');
            		start_dialog2('err_msg',2,'print_ok_time');
            		return;
        		}               
            }
        	}   
            var ti = self.compute_amount();
            if(ti>-1){
                $('.like-red')[0].innerHTML = ti;
                $('.like-red')[1].innerHTML = ti * 2;
            }
        });
    },
    get_lottery_object : function(){
        var value1 = this.danballs.toString();
        var value2 = this.tuoballs.toString();
        var value = value1+"$"+value2
        var num = this.count;
        if(this.bluerequire != -1){
            value += "|"+this.blueballs.toString();
            num = num * this.blueballs.length; 
        }
        var wanfa = '5';
        var fangshi = this.fangshi;
        return new object(this.formater,value,value,num,fangshi,wanfa,1);
    },   
    validate : function(lo){
    	var x = this.danmax;
        if(this.danballs.length<1){
        	$('#msg_content').html('至少需要选择1个胆码');
        	self.start_dialog2('err_msg',2,'print_ok_time');
            return false;
        }
        if(this.tuoballs.length<1){
        	var n = this.redrequire-this.danballs.length;
        	$('#msg_content').html('至少还需选'+n+'个拖码');
        	self.start_dialog2('err_msg',2,'print_ok_time');
            return false;
        }      
        if(this.tuoballs.length+this.danballs.length<this.redrequire){
        	$('#msg_content').html('胆码和拖码的个数不能少于'+this.redrequire+'个');
        	self.start_dialog2('err_msg',2,'print_ok_time');
            return false;
        }
        if(this.bluerequire != -1){
        if(this.blueballs.length<1){
        	$('#msg_content').html('至少选择1个蓝球');
        	self.start_dialog2('err_msg',2,'print_ok_time');
            return false;
        }
        }
        if(parseInt($('.like-red')[0].innerHTML)<=1){
        	$('#msg_content').html('胆托玩法最少投注两注以上');
        	self.start_dialog2('err_msg',2,'print_ok_time');
            return false;
        }
        return true;
    }
});

var dongfang = mathine.$extend({
    __init__ : function(args){
        this.$super(args);
        this.sxnummax = args.sxnummax;
        this.sxrequire = args.sxrequire;
        this.sxmax = args.sxmax;
        this.yiwei = [];
        this.erwei = [];
        this.sanwei = [];
        this.siwei = [];
        this.wuwei = [];
        this.liuwei = [];
        this.shengxiao = [];
    },
    validate : function(lo){
        var vali = true;
        var vali1 = true;
        vali = this.yiwei.length<1||this.erwei.length<1||this.sanwei.length<1||this.siwei.length<1||this.wuwei.length<1||this.liuwei.length<1;
        vali1 = this.shengxiao.length<1;
        if(vali){ 
        		$('#msg_content').html('每位至少选择1个号码球');
            	self.start_dialog2('err_msg',2,'print_ok_time');
                return false;
        	}
        if(vali1){ 
    		$('#msg_content').html('至少选择1个生肖球');
        	self.start_dialog2('err_msg',2,'print_ok_time');
            return false;
    	}
        return true;
    },
    get_html_with_unit : function (){
    	return this.yiwei.join('') + "," + this.erwei.join('') + "," + this.sanwei.join('') + "," + this.siwei.join('')+ "," + this.wuwei.join('')+ "," + this.liuwei.join('')+"|" + this.shengxiao.join(','); 
    },
    get_value_with_unit : function (){
    	var l = this.shengxiao.length;
    	for (var i=0,l=this.shengxiao.length; i<l; i++){
    		switch(this.shengxiao[i])
            {
               case "鼠":
            	   this.shengxiao[i] = "1"
                 break;
               case "牛":
            	   this.shengxiao[i] = "2"
                 break;
               case "虎":
            	   this.shengxiao[i] = "3"
                 break;
               case "兔":
            	   this.shengxiao[i] = "4"
                 break;
               case "龙":
            	   this.shengxiao[i] = "5"
                 break;
               case "蛇":
            	   this.shengxiao[i] = "6"
                 break;
               case "马":
            	   this.shengxiao[i] = "7"
                 break;
               case "羊":
            	   this.shengxiao[i] = "8"
                 break;
               case "猴":
            	   this.shengxiao[i] = "9"
                 break;
               case "鸡":
            	   this.shengxiao[i] = "10"
                 break;
               case "狗":
            	   this.shengxiao[i] = "11"
                 break;
               case "猪":
            	   this.shengxiao[i] = "12"
                 break;
            }
    	}
    	return this.yiwei.join('') + "," + this.erwei.join('') + "," + this.sanwei.join('') + "," + this.siwei.join('')+ "," + this.wuwei.join('')+ "," + this.liuwei.join('')+"|" + this.shengxiao.join(',');
    },
    get_lottery_object : function(){
        var html = this.get_html_with_unit(); //列表显示
        var value = this.get_value_with_unit(); //传到后台的值
        var num = this.count;
        var wanfa = num>1?'2':'1';//1-单注,2-复式
        var fangshi = this.fangshi;
        return new object(this.formater,value,html,num,fangshi,wanfa,1);
    },
    selectball : function(){
        this.yiwei = this.get_balls('.yiwei > i.icon-red-1');
        this.erwei = this.get_balls('.erwei > i.icon-red-1');
        this.sanwei = this.get_balls('.sanwei > i.icon-red-1');
        this.siwei = this.get_balls('.siwei > i.icon-red-1');
        this.wuwei = this.get_balls('.wuwei > i.icon-red-1');
        this.liuwei = this.get_balls('.liuwei > i.icon-red-1');
        this.shengxiao = this.get_balls('.shengxiao > i.icon-red');
        this.count = this.yiwei.length * this.erwei.length * this.sanwei.length * this.siwei.length* this.wuwei.length* this.liuwei.length* this.shengxiao.length;
        return this.yiwei.length>0&&this.erwei.length>0&&this.sanwei.length>0&&this.siwei.length>0&&this.wuwei.length>0&&this.liuwei.length>0&&this.shengxiao.length>0;  //至少满足一注      
    },
    reset : function(){
        var a = ["yiwei","erwei","sanwei","siwei","wuwei","liuwei"];
        for (var i=0;i<a.length;i=i+1){
        	$('.'+a[i]+' i').attr('class','icon-white1');
        }
    	$('.shengxiao i').attr('class','icon-white');
        $('.like-red')[0].innerHTML = 0;
        $('.like-red')[1].innerHTML = 0;
        this.yiwei = [];
        this.erwei = [];
        this.sanwei = [];
        this.siwei = [];
        this.wuwei = [];
        this.liuwei = [];
        this.shengxiao = [];
        this.count = 0;
    },
});

function update_coin(num){
    $('.toubi_geshu_in').html(num);
}

function coin_complete(){
    lottery.buy_lottery(1);
}

function update_password(status){ //用户输入密码后，在界面上提现出字符
	if(status==1){
		var $pwd = $(".bankpassword");
		value=$pwd.val()
    	$pwd.val(value+"*");
	}else if(status==2){
		value=$(".bankpassword").val()
    	$(".bankpassword").val("")
	}else if(status==3){ //取消密码输入
		$('#msg_content').html('交易取消');
		start_dialog2('err_msg',2,'print_ok_time');
	}else if(status==0){ //密码输入超时
		$('#msg_content').html('密码输入超时，请重新刷卡');
		start_dialog2('err_msg',2,'print_ok_time');
	}
}

function complete_password(){
	var card_number = $('#bank_code').val();
	var pay_money = $('.pay_num').html();
	result = pyObj.yeepay_consume(pay_money,card_number);
	if(result=='00'){ //刷卡成功
		lottery.buy_lottery(0)
	}else if(result=='14'){
		$('#msg_content').html("无效卡");
		start_dialog2('err_msg',5,'print_ok_time');
	}else if(result=='54'){
		$('#msg_content').html("过期卡");
		start_dialog2('err_msg',5,'print_ok_time');
	}else if(result=='55'){
		$('#msg_content').html("密码错误");
		start_dialog2('err_msg',5,'print_ok_time');
	}else if(result=='31'){
		$('#msg_content').html("银联不支持的卡");
		start_dialog2('err_msg',5,'print_ok_time');
	}else if(result=='38'){
		$('#msg_content').html("密码错误次数过多");
		start_dialog2('err_msg',5,'print_ok_time');
	}else if(result=='51'){
		$('#msg_content').html("余额不足");
		start_dialog2('err_msg',5,'print_ok_time');
	}else if(result=='61'){
		$('#msg_content').html("超出限额");
		start_dialog2('err_msg',5,'print_ok_time');
	}else if(result=='57'){
		$('#msg_content').html("不允许交易，联系支付中心");
		start_dialog2('err_msg',5,'print_ok_time');
	}else{
		$('#msg_content').html("交易失败,错误码:"+result);
		start_dialog2('err_msg',5,'print_ok_time');
	}
}

function version_updating(){
	$('#msg_content').html("发现新版本，正在升级...");
	start_dialog2('err_msg',300,'print_ok_time');
}

function network_status(status){
	if(status==1){
		$("#errors_tip").attr("style","display:block;")
	}else if(status==0){
		$("#errors_tip").attr("style","display:None;")
	}
}

function close_toubi(){
	pyObj.clear_total();
	easyDialog.close();
}